package com.gadgets.busi.bm01.task.hook;

import com.gadgets.busi.bm01.common.event.GadgetsBm01TaskStartEvent;
import com.gadgets.busi.bm01.dto.TxtCopyStatusChangeDTO;
import com.gadgets.framework.common.constant.GadgetsConstant;
import org.springframework.stereotype.Component;

/**
 * The type Task start hook.
 *
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020 -09-21
 */
@Component(value = "bm01TaskStartHook")
public class TaskStartHook extends AbstractBm01TaskHook<GadgetsBm01TaskStartEvent> {

    /**
     * 任务执行钩子
     *
     * @param event 事件信息
     */
    @Override
    public void excuteHook(GadgetsBm01TaskStartEvent event) {
        logger.info("{}钩子开始调度",this.getClass().getName());
        if(null==event){
            logger.error("事件信息为空，无法执行任务钩子，执行被终止...");
        }else {
            // 更新任务状态
            TxtCopyStatusChangeDTO changeDTO = new TxtCopyStatusChangeDTO();
            changeDTO.setTaskNo(event.getTaskNo());
            changeDTO.setBeforeStatus(new String[]{GadgetsConstant.TASK_STATUS.EXCUTE});
            changeDTO.setAfterStatus(GadgetsConstant.TASK_STATUS.EXCUTE);
            copyTxtTaskRepository.updateTaskStatus(changeDTO);
        }
    }

}
